package com.system.presideover.controller;


import com.system.common.result.Result;
import com.system.presideover.entity.AuctionCalendar;
import com.system.presideover.service.AuctionCalendarService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 档期类型 前端控制器
 * </p>
 *
 * @author system
 * @since 2024-04-16
 */
@Api(tags = "档期类型")
@RestController
@RequestMapping("/presideover/auction-calendar")
public class AuctionCalendarController {

    @Autowired
    private AuctionCalendarService auctionCalendarService;

    @ApiOperation(value = "档期类型")
    @GetMapping("/listAuctionCalendar")
    public Result listAuctionCalendar(){
        List<AuctionCalendar> list = auctionCalendarService.list();
        return Result.ok(list);
    }

    @ApiOperation(value = "添加档期类型")
    @PostMapping("/saveAuctionCalendar")
    public Result saveAuctionCalendar(@RequestBody AuctionCalendar accountNumber){
        accountNumber.setCreateTime(LocalDateTime.now());
        boolean save = auctionCalendarService.save(accountNumber);

        if (save){
            return Result.ok().message("添加成功");
        }
        return Result.fail().message("添加失败");
    }


    @ApiOperation(value = "修改档期类型")
    @PostMapping("/updateAccountNumber")
    public Result updateAccountNumber(@RequestBody AuctionCalendar accountNumber){

        accountNumber.setUpdateTime(LocalDateTime.now());
        boolean save = auctionCalendarService.updateById(accountNumber);

        if (save){
            return Result.ok().message("修改成功");
        }
        return Result.fail().message("修改失败");
    }

    @ApiOperation(value = "删除档期类型")
    @PostMapping("/delectAccountNumber")
    public Result delectAccountNumber(@RequestBody AuctionCalendar accountNumber){
        boolean save = auctionCalendarService.removeById(accountNumber.getId());

        if (save){
            return Result.ok().message("删除成功");
        }
        return Result.fail().message("删除失败");
    }

}

